package com.acc.softmgr.business.controller;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.acc.softmgr.business.model.SysDict;
import com.acc.softmgr.business.model.SysDictExample;
import com.acc.softmgr.business.service.ISysDictService;
import com.acc.softmgr.common.web.SelectLabel;

@Controller
@RequestMapping("sysDict")
public class SysDictController {

	@Autowired
	private ISysDictService sysDictService;

	/**
	 * 查询下拉选项框
	 * 
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/searchSelectPsDicts", method = { RequestMethod.GET, RequestMethod.POST })
	@ResponseBody
	public List<SelectLabel> searchSelectPsDicts(@Validated String moudle) throws Exception {
		SysDictExample example = new SysDictExample();
		example.getCriteria().andPs_moudleEqualTo(moudle);
		List<SysDict> sysDicts = sysDictService.selectByExample(example);
		List<SelectLabel> selectLabels = new ArrayList<SelectLabel>();
		for (SysDict dict : sysDicts) {
			SelectLabel selectLabel = new SelectLabel(dict.getPs_value(), dict.getPs_key());
			selectLabels.add(selectLabel);
		}
		return selectLabels;
	}
}
